<% @page_title = @topic.title %>
<% @monitoring = logged_in? && !Monitorship.count(:id, :conditions => ['user_id = ? and topic_id = ? and active = ?', current_user.id, @topic.id, true]).zero? %>

<% content_for :right do -%>

<h5><%= 'Voices'[:voices_title] %></h5>
<ul class="flat talking">
<% @topic.voices.each do | user | %>
  <li><%= link_to h(user.display_name), user_path(user) %></li>
<% end %>
</ul>


<% end # right content -%>

<% if logged_in? %>
<% form_tag forum_topic_monitorship_path(@forum, @topic), :style => 'margin-top:0em; float:right;' do -%>
<div>
  <input id="monitor_checkbox" type="checkbox" <%= "checked='checked'" if @monitoring %> 
    onclick="if (this.checked) {<%= remote_function :url => forum_topic_monitorship_path(@forum, @topic) %>} else {<%= remote_function :url => forum_topic_monitorship_path(@forum, @topic), :method => :delete %>}" />
  <label id="monitor_label" for="monitor_checkbox"><%= @monitoring ? 'Monitoring topic'[] : 'Monitor topic'[] %></label>
  <%= hidden_field_tag '_method', 'delete' if @monitoring %>
  <%= submit_tag :Set, :id => 'monitor_submit' %>
</div>
<% end -%>

<% end -%>


<div class="crumbs">
  <%= link_to "Forums"[:forums_title], forums_path %> <span class="arrow">&rarr;</span>
  <%= link_to h(@topic.forum.name), forum_path(@topic.forum) %> 
  <% 
  page=session[:forum_page] ? session[:forum_page][@topic.forum.id] : nil
  if page and page!=1 %>
  <small style="color:#ccc">
  (<%= link_to 'page {page}'[:page, page], forum_path(:id => @topic.forum, :page => page) %>)
  </small>
  <% end %>
  <span class="arrow">&rarr;</span>
</div>

<h1 id="topic-title" style="margin-top:0.5em;"<%= %( onmouseover="$('topic_mod').show();" onmouseout="$('topic_mod').hide();") if logged_in? %>>


  <%= h @topic.title %>
  <% if @topic.locked? %>
  <span>(<%= 'locked'[] %>)</span>
  <% end %>
  <% if logged_in? %>
    <span style="display:none;" id="topic_mod">
      <% if @topic.editable_by?(current_user) -%>
        <%= link_to('edit'[], edit_forum_topic_path(@forum, @topic), :class => "utility") %> |
        <%= link_to('delete'[], forum_topic_path(@forum, @topic), :class => "utility", :method => :delete, :confirm => 'Delete this topic forever?'[:delete_topic_conf]) %>
      <% end -%>
    </span>
  <% end %>
</h1>

<p class="subtitle">
  <%= feed_icon_tag @topic.title, formatted_forum_topic_path(@forum, @topic, :rss) %>
  <%= '{count} post(s)'[(count=@topic.posts.size)==1 ? :post_count : :posts_count, number_with_delimiter(count)] %>, 
  <%= '{count} voice(s)'[(count=@topic.voices.size)==1 ? :voice_count : :voices_count, number_with_delimiter(count)] %>
</p>

<%= pagination @posts %>

<a name="<%= dom_id @posts.first %>" id="<%= dom_id @posts.first %>">&nbsp;</a>

<table border="0" cellspacing="0" cellpadding="0" class="posts wide">
<% for post in @posts do %>
<% unless post == @posts.first %>
<tr class="spacer">
  <td colspan="2">
    <a name="<%= dom_id post %>" id="<%= dom_id post %>">&nbsp;</a>
  </td>
</tr>
<% end %>
<tr class="post hentry" id="<%= dom_id post %>-row">
  <td class="author vcard">
    <div class="date">
      <a href="#<%= dom_id post %>" rel="bookmark">
      <abbr class="updated" title="<%= post.created_at.xmlschema %>">
      <%= time_ago_in_words(post.created_at) %>
      </abbr>
      </a>
    </div>

    <%= avatar_for post.user %>
    <span class="fn"><%= link_to truncate(h(post.user.display_name), 15), user_path(post.user), :class => (post.user == @posts.first.user ? "threadauthor" : nil) %></span>
    <% if post.user.admin? or post.forum.moderators.include?(post.user) %>
    <span class="admin">
      <% if post.user.admin? %>
      <%= 'Administator'[:administrator_title] %>
      <% elsif post.forum.moderators.include?(post.user) %>
      <%= 'Moderator'[:moderator_title] %>
      <% end %>
    </span>
    <% end %>
    <span class="posts"><%= '{count} post(s)'[(count=post.user.posts.size)==1 ? :post_count : :posts_count, number_with_delimiter(count)] %></span>


    <% if logged_in? && post.editable_by?(current_user) -%>
    <p>
      <span class="edit">
        <%= ajax_spinner_for "edit-post-#{post.id}", "spinner_bounce.gif" %>
        <%= link_to_remote('Edit post'[], 
              {:url => edit_post_path(:forum_id => @forum, :topic_id => @topic, :id => post), :method => :get,
               :before => "EditForm.init(#{post.id});", :condition => "!EditForm.isEditing(#{post.id})" }, 
              {:href => edit_post_path(:forum_id => @forum, :topic_id => @topic, :id => post, :page => params[:page]), :class => "utility"}) %>
      </span>
    </p>
    <% end -%>


  </td>
  <td class="body entry-content" id="post-body-<%= post.id %>">
<!--
    <%= link_to_function image_tag('clearbits/comment.gif', :class => 'icon reply'), "$('reply').toggle()" if logged_in? %>
-->
    <%= post.body_html %>
  </td>
</tr>

<% end %>
</table>
       
<%= next_page @posts %>
<%= pagination @posts %>

<% if logged_in? %>
<div id="edit"></div>
<% if @topic.locked? %>
<p>
    <%= image_tag "clearbits/lock.gif", :class => "icon grey", :title => "Topic locked"[:topic_locked_title], :plugin => "savage_beast" %> 
    <label>
    <%= 'This topic is locked'[:locked_topic] %>.</label>
</p>
<% else %>

<p><%= link_to_function 'Reply to topic'[], "ReplyForm.init()", :class => "utility" %></p>

<div id="reply" class="editbox">
<div class="container">
  <%= content_tag 'p', h(flash[:bad_reply]), :class => 'notice' if flash[:bad_reply] %>
  <% form_for :post, :url => posts_path(:forum_id => @forum, :topic_id => @topic, :page => @topic.last_page) do |f| -%>
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td rowspan="2" width="70%">
        <%= f.text_area :body, :rows => 8 %>
      </td>
      <td valign="top">


        <h5><%= 'Formatting Help'[] %></h5>

        <ul class="help">
          <li><%= '*bold*'[:formatting_bold] %>
          &nbsp; &nbsp; &nbsp;
          <%= '_italics_'[:formatting_italics] %>
          &nbsp; &nbsp; &nbsp;<br />
          <%= 'bq. <span>(quotes)</span>'[:formatting_blockquote] %></li>
          <li>"IBM":http://www.ibm.com</li>
          <li><%= '* or # <span>(lists)</span>'[:formatting_list] %></li>
        </ul>

      </td>
    </tr>
    <tr>
      <td valign="bottom" style="padding-bottom:15px;">
       <%= submit_tag "Save Reply"[] %><span class="button_or">or <%= link_to_function 'cancel'[], "$('reply').hide()" %></span>
     </td>
   </tr>
  </table>
  <% end -%>
</div>
</div>
<%= javascript_tag "$('reply').hide();"%>
<% end %>
<% end %>

<div class="crumbs" style="margin-top:1.1em;">
  <%= link_to "Forums"[:forums_title], forums_path %> <span class="arrow">&rarr;</span>
  <%= link_to h(@topic.forum.name), forum_path(@topic.forum) %> <span class="arrow">&rarr;</span>
</div>
